﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using System.Web.Security;
using System.Text;
using LogicLevel;

namespace WebLevel
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            TB_EMAIL.Text = null;
            TB_USERNAME.Text = null;
            TB_PASSWORD.Text = null;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            bool boo = new Regex(@"[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})").Match(TB_EMAIL.Text).Success;
            if (boo)
            {
                MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                String pwd = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(TB_PASSWORD.Text)), 4, 8).ToLower();
                pwd = pwd.Replace("-", "");
                if (UserMethod.userRegister(TB_EMAIL.Text, TB_USERNAME.Text, pwd) != 0)
                {
                    Response.Write("<script>alert('注册成功，请尽快登录邮箱验证！');</script>");
                }
                else
                    Response.Write("<script>alert('注册失败，请重试！');</script>");
            }
            else
            {
                Response.Write("<script>alert('邮箱输入格式有误！');</script>");
            }
        }
    }
}